const formatTime = (date, format = 0) => {
  date = new Date(date)
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  let ret = ''
  if (format === 0) {
    ret = [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
  } else if (format === 1) {
    ret = `${formatNumber(year)}年${formatNumber(month)}月${formatNumber(day)}日`
  }


  return ret
}

const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : '0' + n
}

const formatAmount = num => {
	num = parseInt(num);

	if (num >= 10000){
		let floatNum = (num / 10000).toFixed(2);
		let arr = (num / 10000).toFixed(2).split('.');
		if (arr[1] != '00') {
			return floatNum + 'w';
		} else {
			return arr[0] + 'w';
		}
	} else {
		return num;
	}
	// return num >= 10000 ? (num / 10000).toFixed(2) : num;
}

module.exports = {
  formatTime: formatTime,
	formatAmount: formatAmount
}
